﻿using CatUtils.Utils.Currency.IoUtils;

using CatUtils.Utils.Helper;
using CatUtils.Utils.SpecialUtils.PicBed.Sina;
using CatUtils.Utils.SpecialUtils.View;
using RabbitDownload.Helper;
using RabbitDownload.Helper.ViewHelper;
using RabbitDownload.ViewcCntrol;
using RabbitDownload.WebSite;
using RabbitDownload.WebSite.Local;
using RabbitDownload.WebSite.Local.AutoPic;
using RabbitDownload.WebSite.Pixiv.PixivTag;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RabbitDownload
{
    public partial class MainView : Form
    {
        public MainView(String[] CmdValue)
        {
            InitializeComponent();
            InitViewAsync(CmdValue);
        }

        /// <summary>
        /// 初始化程序相关
        /// </summary>
        private async System.Threading.Tasks.Task InitViewAsync(String[] CmdValue)
        {
            ComboboxSelectChange.InitGroupBox(groupBox1);
            FloderHelper.FloderExits(StaticValueOld.DownloadPath, true);
            FloderHelper.FloderExits(StaticValueOld.OldLogPath, true);

            FloderHelper.InitFloder();
            new SiteSqlliteTool().InitSqllite();
            new ViewMemoryHelper().InItCheckBox(ViewMemoryHelper.DownloadList, checkBox1);
            new ViewMemoryHelper().InItCheckBox(ViewMemoryHelper.DownloadAuto, checkBox2);
            StaticValueOld.SaveImgListFlag = checkBox1.Checked;
            StaticValueOld.AutosaveImgListFlag = checkBox2.Checked;

            if (CmdValue.Length > 0)
                backgroundWorker1.RunWorkerAsync();
            await Groupboxhelper.InitAll(groupBox1, comboBox1, ComboboxSelectChange.MainList, Groupboxhelper.DefaultViewName);
            ComboboxSelectChange.SelectChange(groupBox1, comboBox1, comboBox1.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FloderHelper.OpenFloder(".\\");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboboxSelectChange.SelectChange(groupBox1, comboBox1, comboBox1.Text);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            StaticValueOld.SaveImgListFlag = checkBox1.Checked;

            new ViewMemoryHelper().CheckBoxChanged(ViewMemoryHelper.DownloadList, checkBox1);
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            StaticValueOld.AutosaveImgListFlag = checkBox2.Checked;
            new ViewMemoryHelper().CheckBoxChanged(ViewMemoryHelper.DownloadAuto, checkBox2);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            PixivTagJsonNew.ListFileBatch(FileHelper.SelectFile());
            ///PixivTagJsonNew.Scanner("少女", 1, 2, "popular_male_d", "r18", 1000, true);
            //new PixivLoginForm("https://pixiv.net").Show();
            //new PixivBackgroundRun().ScannerDayMale();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            FloderHelper.OpenFloder(StaticValueOld.DownloadPath);
        }

        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Console.WriteLine("运行程序");
            new ServerHelper().StartRun(label1, sender, e, backgroundWorker1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Console.WriteLine("点击取消");
            backgroundWorker1.CancelAsync();
        }
    }
}